package com.example.task1.ui.AllService.hospital;

import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.base.BaseActivity;
import com.example.task1.bean.HospitalOrderBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import retrofit2.Call;

public class HospitalOrderActivity extends BaseActivity {

    private RecyclerView rvList;
    private HospitalOrderAdapter hospitalOrderAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hospital_order);
        initView();
        initData();
        setAdapter();
    }

    private void setAdapter() {
        hospitalOrderAdapter = new HospitalOrderAdapter();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        rvList.setAdapter(hospitalOrderAdapter);
        rvList.setLayoutManager(linearLayoutManager);
    }

    private void initData() {
        Call<ApiResp> apiRespCall = Api.api().get(MyApplication.TOKEN, "/prod-api/api/hospital/reservation/list");
        Api.send(apiRespCall, HospitalOrderBean.class, new CallBack<HospitalOrderBean>() {
            @Override
            public void success(HospitalOrderBean data) {
                hospitalOrderAdapter.setData(data.getRows());
            }

            @Override
            public void error(String msg) {

            }
        });
    }

    @Override
    public String getMyTitle() {
        return "预约问诊订单列表";
    }

    private void initView() {
        rvList = (RecyclerView) findViewById(R.id.rv_list);
    }
}